package com.wn.service.impl;

import com.wn.dao.SurroundingsDao;
import com.wn.entity.Surroundings;
import com.wn.service.SurroundingsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Surroundings)表服务实现类
 *
 * @author makejava
 * @since 2020-10-26 09:41:08
 */
@Service("surroundingsService")
@Transactional(rollbackFor = Exception.class)
public class SurroundingsServiceImpl implements SurroundingsService {
    @Resource
    private SurroundingsDao surroundingsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Surroundings queryById(String id) {
        return this.surroundingsDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Surroundings> queryAllByLimit(int offset, int limit) {
        return this.surroundingsDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param surroundings 实例对象
     * @return 实例对象
     */
    @Override
    public Surroundings insert(Surroundings surroundings) {
        this.surroundingsDao.insert(surroundings);
        return surroundings;
    }

    /**
     * 修改数据
     *
     * @param surroundings 实例对象
     * @return 实例对象
     */
    @Override
    public Surroundings update(Surroundings surroundings) {
        this.surroundingsDao.update(surroundings);
        return this.queryById(surroundings.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.surroundingsDao.deleteById(id) > 0;
    }
}